package com.ddzh.service;

import com.ddzh.feign.OrderFeignApi;
import com.ddzh.feign.UserFeignApi;
import com.ddzh.pojo.Order;
import com.ddzh.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConsumerService {

    @Autowired
    private OrderFeignApi orderFeignApi;

    @Autowired
    private UserFeignApi userFeignApi;

    public Map<String, List<Order>> findUserById(String username){
        //根据用户名查询订单集合
        List<Order> orderList = orderFeignApi.findOrderByUserId(username);
        System.out.println("orderList = " + orderList);
        //根据用户名查找用户信息
        User user = userFeignApi.findUserById(username);
        System.out.println("user = " + user);
        //返回封装的结果集：用户和订单信息
        Map<String, List<Order>> resMap = new HashMap<>();
        resMap.put(username,orderList);
        return resMap;
    }
}
